//
//  WKReportViewController.m
//  Walk
//
//  Created by cesh on 16/9/6.
//  Copyright © 2016年 cesh. All rights reserved.
//

#import "WKReportViewController.h"

@interface WKReportViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *backImg;
@property (weak, nonatomic) IBOutlet UIButton *btn1;
@property (weak, nonatomic) IBOutlet UIButton *btn2;
@property (weak, nonatomic) IBOutlet UIButton *btn3;
@property (weak, nonatomic) IBOutlet UIButton *btn4;
@property (weak, nonatomic) IBOutlet UIButton *btn5;

@end

@implementation WKReportViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.backImg.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapOnBackImg = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(back)];
    [self.backImg addGestureRecognizer:tapOnBackImg];
}

- (void)back {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)reportBtn:(UIButton *)button {
    button.selected = !button.isSelected;
}

- (IBAction)commitBtn:(id)sender {
    //上传举报信息
    
    AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
    mgr.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",
                                                      @"text/html",
                                                      @"image/jpeg",
                                                      @"image/png",
                                                      @"application/octet-stream",
                                                      @"text/json",
                                                      nil];
    
    NSString *postURL = self.reportType == ReportTypeUser ? @"Frog/reportUser" : @"Frog/reportEvent";
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    if (self.reportType == ReportTypeUser) {
        [dict setValue:self.user_id forKey:@"uid"];
    }
    else {
        [dict setValue:self.event_id forKey:@"eid"];
    }
    NSMutableArray *types = [NSMutableArray array];
    if (self.btn1.isSelected) {
        [types addObject:[NSString stringWithFormat:@"%li", (long)self.btn1.tag]];
    }
    if (self.btn2.isSelected) {
        [types addObject:[NSString stringWithFormat:@"%li", (long)self.btn2.tag]];
    }
    if (self.btn3.isSelected) {
        [types addObject:[NSString stringWithFormat:@"%li", (long)self.btn3.tag]];
    }
    if (self.btn4.isSelected) {
        [types addObject:[NSString stringWithFormat:@"%li", (long)self.btn4.tag]];
    }
    if (self.btn5.isSelected) {
        [types addObject:[NSString stringWithFormat:@"%li", (long)self.btn5.tag]];
    }
    
    [dict setValue:types forKey:@"reportType"];
    
    [mgr POST:[NSString stringWithFormat:@"%@%@", URL, postURL] parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"举报成功 %@", responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"举报失败 %@", error);
    }];
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
